import React, {Component} from 'react';
import {
  Layout,
  Menu,
  Breadcrumb,
  Modal,
  Form,
  Input,
  Select,
  DatePicker,
  Popconfirm,
  Card,
  Row,
  Col,
  Button,
  Radio,
  Dropdown,
  Icon,
  Upload,
  message,
  Table,
  Pagination,
  Checkbox
} from 'antd';
const FormItem = Form.Item;
const {Header, Content, Footer} = Layout;
import _ from 'underscore';
import WrapPage from './_wrap'
import styles from './main.less'
const Option = Select.Option;
import * as UserModel from '../model/user';
import { Link } from 'dva/router';

let user = {}//JSON.parse(localStorage.user);
class _Page extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  async updateUser() {
    let values = this.props.form.getFieldsValue()
    delete values.phone
    values.to_user=[user.cnum]
    values.note = user.name+"个人资料修改成功";
    values.action = "修改"
    let n = await UserModel.updateByNum(user.cnum,values)
    if(n.status == 'success'){
      message.success('更新成功🙂');
    }
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 8 },
    };
    return (
      <WrapPage>
      <Form >
      <FormItem {...formItemLayout} label="手机号">
      {getFieldDecorator('phone', {initialValue:user.phone})(<Input disabled={true} size="small" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="姓名">
      {getFieldDecorator('name', {initialValue:user.name})(<Input size="small" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="邮箱">
      {getFieldDecorator('email', {initialValue:user.email})(<Input size="small" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="职务">
      {getFieldDecorator('job', {initialValue:user.job})(<Input size="small" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="部门">
      {getFieldDecorator('department', {initialValue:user.department})(<Input size="small" />)}
      </FormItem>
      <FormItem {...formItemLayout} label="公司">
      {getFieldDecorator('company', {initialValue:user.company})(
      <Radio.Group>
      {['总部','北京','杭州','武汉','上海'].map(v=> <Radio key={v} value={v}>{v}</Radio>)}
      </Radio.Group>
      )}
      </FormItem>
      <FormItem wrapperCol={{ span: 16, offset: 8 }}>
      <Button type="primary" size="large" style={{marginRight:'20px'}} title="返回" ><Link to={"/account"} ><Icon type="caret-left" /></Link></Button>
      <Button type="primary" size="large" onClick={e=>this.updateUser()}>更改</Button>
      </FormItem>
      </Form>
      </WrapPage>
      );
  }
}

export default Form.create()(_Page)